package com.project.web.course.controller.common;

import com.project.common.core.utils.exception.Result;
import com.project.common.core.utils.file.FilePathConsts;
import com.project.common.core.utils.file.FileUtil;
import com.project.common.core.utils.redis.RedisClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

/**
 * 公共接口API
 *
 * @author wyy
 * @date 2020-04-15
 */
@Api(tags = "公共API")
@RestController("courseServiceCommonController")
@RequestMapping("/course/common")
public class CommonController extends BaseController {

    @Resource(name = "redisClient")
    private RedisClient redisClient;

    /**
     * 上传文件到NFS服务器，获取NFS临时文件名称
     *
     * @param file 文件
     * @return
     */
    @ApiOperation(value = "上传文件到NFS服务器，获取NFS临时文件名称")
    @ApiImplicitParams(
            @ApiImplicitParam(paramType = "query", name = "file", value = "上传文件", required = true, dataType = "MultipartFile"))
    @PostMapping(value = "/getNFSFileName")
    public Result<String> getNFSFileName(MultipartFile file) {
        String orgFileName = FileUtil.getNFSFileName(file);
        return getResult(orgFileName);
    }

    /**
     * 上传文件到NFS服务器，获取NFS文件名称
     *
     * @param file 文件
     * @return
     */
    @ApiOperation(value = "上传文件到NFS服务器，获取NFS文件名称")
    @ApiImplicitParams(
            @ApiImplicitParam(paramType = "query", name = "file", value = "上传文件", required = true, dataType = "MultipartFile"))
    @PostMapping(value = "/getNFSFilePath")
    public Result<String> getNFSFilePath(MultipartFile file) {
        String nfsUri = FileUtil.getNFSUrl(file, FilePathConsts.COURSE_CATEGORY_PATH);
        return getResult(nfsUri);
    }
}
